<template>
  <div class="cate">
    <!-- 面包屑导航区域啊---jdsh - -->
    <Breadcrumb name1="商品管理" name2="商品分类" />
    <!-- 卡片视图区域 -->
    <el-card>
      <el-row>
        <el-button type="primary" @click="showAddCateDialog">添加分类</el-button>
      </el-row>
      <el-row>
        <!-- 表格 -->
        <tree-table :data="cateList" :expand-type="false" :selection-type="false" show-index class="treetable" index-text="#" stripe border :show-row-hover="false" :columns="columns">
          <!-- 是否有效 -->
          <!-- <template slot='isok' v-slot="scope"> -->
          <template v-slot:isok="scope">
            <i class="el-icon-success" v-if="scope.row.cat_deleted === false" style="color: lightgreen"></i>
            <i class="el-icon-error" style="color: red" v-else></i>
          </template>
          <!-- 排序 -->
          <template v-slot:order="scope">
            <el-tag size="mini" v-if="scope.row.cat_level === 0">一级</el-tag>
            <el-tag size="mini" type="success" v-else-if="scope.row.cat_level === 1">二级</el-tag>
            <el-tag size="mini" type="warning" v-else>三级</el-tag>
          </template>
          <template v-slot="scope">
            <el-button type="primary" @click="showeditCateDialog(scope.row)" icon="el-icon-edit" size="mini">编辑</el-button>
            <el-button type="danger" @click="removeCate(scope.row.cat_id)" icon="el-icon-delete" size="mini">删除</el-button>
          </template>
        </tree-table>
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[3, 5, 10, 15]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
    </el-card>
    <!-- 添加分类的对话框   -->
    <el-dialog title="添加分类" :visible.sync="addCateDialogVisible" width="50%" @close="addCateDialogClosed">
      <el-form :model="addCateForm" :rules="addCateFormRules" ref="addCateFormRef" label-width="100px">
        <el-form-item label="分类名称:" prop="cat_name">
          <el-input v-model="addCateForm.cat_name"></el-input>
        </el-form-item>
        <el-form-item label="父级分类:">
          <!-- options 用来指定数据源 -->
          <!-- props 用来指定配置对象 -->
          <el-cascader
            v-model="selectdKeys"
            :options="parentCateList"
            :props="{
              expandTrigger: 'hover',
              ...cascaderProps,
              checkStrictly: 'true'
            }"
            @change="parentCateChanged"
            clearable
          ></el-cascader>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addCateDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addCate">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 编辑分类信息 -->
    <el-dialog title="修改分类" :visible.sync="editCateDialogVisbel" width="50%">
      <el-form :model="editCate" :rules="editCateRules" ref="editCateRef" label-width="100px">
        <el-form-item label="分类名称" prop="cat_name">
          <el-input v-model="editCate.cat_name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editCateDialogVisbel = false">取 消</el-button>
        <el-button type="primary" @click="editCateInfo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Breadcrumb from 'components/content/breadcrumb/Breadcrumb'
export default {
  name: 'Cate',
  components: {
    Breadcrumb // 面包屑
  },
  data() {
    return {
      // 商品分类的数据列表,默认为空
      cateList: [
        {
          cat_deleted: false,
          cat_id: 1,
          cat_level: 0,
          cat_name: "外科用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 3,
              cat_level: 1,
              cat_name: "外涂药液",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 4,
                  cat_level: 2,
                  cat_name: '跌打损伤',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 5,
                  cat_level: 2,
                  cat_name: '消炎镇痛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 6,
                  cat_level: 2,
                  cat_name: '冷敷外用  ',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 7,
                  cat_level: 2,
                  cat_name: '止痛止痒',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 3,
              cat_level: 1,
              cat_name: "外涂软膏",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 4,
                  cat_level: 2,
                  cat_name: '抗过敏',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 5,
                  cat_level: 2,
                  cat_name: '抗真菌',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 6,
                  cat_level: 2,
                  cat_name: '顽固性皮炎',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 7,
                  cat_level: 2,
                  cat_name: '消炎消肿外用',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 8,
              cat_level: 1,
              cat_name: "外用器械",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 9,
                  cat_level: 2,
                  cat_name: '拐杖',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 10,
                  cat_level: 2,
                  cat_name: '轮椅',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 11,
                  cat_level: 2,
                  cat_name: '石膏支架',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 12,
                  cat_level: 2,
                  cat_name: '脊柱固定器',
                  cat_pid: 3
                },

              ]
            },{
              cat_deleted: false,
              cat_id: 13,
              cat_level: 1,
              cat_name: "应急用品",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 14,
                  cat_level: 2,
                  cat_name: '外用止痛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 15,
                  cat_level: 2,
                  cat_name: '局部麻醉',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 16,
                  cat_level: 2,
                  cat_name: '封闭针剂',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 17,
                  cat_level: 2,
                  cat_name: '外科碎石',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 18,
                  cat_level: 2,
                  cat_name: '止血收敛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 19,
                  cat_level: 2,
                  cat_name: '镇静安神',
                  cat_pid: 3
                },

              ]
            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 20,
          cat_level: 0,
          cat_name: "内科用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 21,
              cat_level: 1,
              cat_name: "肠胃用药",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 22,
                  cat_level: 2,
                  cat_name: '消化不良',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 23,
                  cat_level: 2,
                  cat_name: '食欲不振',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 24,
                  cat_level: 2,
                  cat_name: '急性肠胃炎',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 25,
                  cat_level: 2,
                  cat_name: '反酸胀气',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 26,
                  cat_level: 2,
                  cat_name: '急性出血',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 27,
              cat_level: 1,
              cat_name: "退烧解热",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 28,
                  cat_level: 2,
                  cat_name: '退烧解热',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 29,
                  cat_level: 2,
                  cat_name: '疏风解表',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 30,
                  cat_level: 2,
                  cat_name: '温度测量',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 31,
              cat_level: 1,
              cat_name: "长期用药",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 32,
                  cat_level: 2,
                  cat_name: '降压药',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 33,
                  cat_level: 2,
                  cat_name: '降血糖',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 34,
                  cat_level: 2,
                  cat_name: '保健养生',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 35,
                  cat_level: 2,
                  cat_name: '疏通血管',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 36,
                  cat_level: 2,
                  cat_name: '皮肤炎症',
                  cat_pid: 3
                },

              ]
            },{
              cat_deleted: false,
              cat_id: 37,
              cat_level: 1,
              cat_name: "呼吸系统用药",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 38,
                  cat_level: 2,
                  cat_name: '气管炎症',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 39,
                  cat_level: 2,
                  cat_name: '肺部炎症',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 40,
                  cat_level: 2,
                  cat_name: '耳鼻喉疾病',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 41,
                  cat_level: 2,
                  cat_name: '胸闷气短',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 42,
                  cat_level: 2,
                  cat_name: '血氧低',
                  cat_pid: 3
                },

              ]
            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 43,
          cat_level: 0,
          cat_name: "神经系统用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 44,
              cat_level: 1,
              cat_name: "睡眠不好",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 45,
                  cat_level: 2,
                  cat_name: '失眠',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 46,
                  cat_level: 2,
                  cat_name: '睡眠质量差，改善睡眠质量',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 47,
                  cat_level: 2,
                  cat_name: '多梦，神经衰弱',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 48,
                  cat_level: 2,
                  cat_name: '烦躁不安，难以入睡',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 49,
              cat_level: 1,
              cat_name: "神经病变",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id:50,
                  cat_level: 2,
                  cat_name: '头部神经系统痛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 51,
                  cat_level: 2,
                  cat_name: '四肢神经痛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 52,
                  cat_level: 2,
                  cat_name: '面部痉挛',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 53,
                  cat_level: 2,
                  cat_name: '行动不便',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 54,
                  cat_level: 2,
                  cat_name: '语言功能丧失',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 54,
                  cat_level: 2,
                  cat_name: '记忆退化',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 55,
              cat_level: 1,
              cat_name: "心理疾病",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 56,
                  cat_level: 2,
                  cat_name: '抑郁症',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 57,
                  cat_level: 2,
                  cat_name: '狂躁症',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 58,
                  cat_level: 2,
                  cat_name: '多重人格',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 59,
                  cat_level: 2,
                  cat_name: '精神分裂',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 60,
                  cat_level: 2,
                  cat_name: '镇定剂',
                  cat_pid: 3
                },
              ]
            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 61,
          cat_level: 0,
          cat_name: "疫情防护",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 62,
              cat_level: 1,
              cat_name: "个人防护",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 63,
                  cat_level: 2,
                  cat_name: '防护口罩',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 64,
                  cat_level: 2,
                  cat_name: '防止飞沫面罩',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 65,
                  cat_level: 2,
                  cat_name: '防护服',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 66,
                  cat_level: 2,
                  cat_name: '防护眼镜',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 71,
                  cat_level: 2,
                  cat_name: '一次性手套',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 67,
              cat_level: 1,
              cat_name: "家庭消毒用品",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 68,
                  cat_level: 2,
                  cat_name: '消毒酒精',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 69,
                  cat_level: 2,
                  cat_name: '紫外线杀菌灯',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 70,
                  cat_level: 2,
                  cat_name: '消毒喷雾',
                  cat_pid: 3
                },

              ]
            },
            {
              cat_deleted: false,
              cat_id: 71,
              cat_level: 1,
              cat_name: "防疫常备药品",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 72,
                  cat_level: 2,
                  cat_name: '退烧药',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 73,
                  cat_level: 2,
                  cat_name: '体温计',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 74,
                  cat_level: 2,
                  cat_name: '止泻药',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 75,
                  cat_level: 2,
                  cat_name: '抗病毒颗粒',
                  cat_pid: 3
                },

              ]
            },{
              cat_deleted: false,
              cat_id: 76,
              cat_level: 1,
              cat_name: "病原体检测",
              cat_pid: 1,
              children:[
                {
                  cat_deleted: false,
                  cat_id: 77,
                  cat_level: 2,
                  cat_name: '测试试纸',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 78,
                  cat_level: 2,
                  cat_name: '自测样品',
                  cat_pid: 3
                },
                {
                  cat_deleted: false,
                  cat_id: 79,
                  cat_level: 2,
                  cat_name: '对照表',
                  cat_pid: 3
                },

              ]
            },
          ]
        },



      ],
      parentCateList: [
        {
          cat_deleted: false,
          cat_id: 1,
          cat_level: 0,
          cat_name: "外科用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 3,
              cat_level: 1,
              cat_name: "外涂药液",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 3,
              cat_level: 1,
              cat_name: "外涂软膏",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 8,
              cat_level: 1,
              cat_name: "外用器械",
              cat_pid: 1,

            },{
              cat_deleted: false,
              cat_id: 13,
              cat_level: 1,
              cat_name: "应急用品",
              cat_pid: 1,

            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 20,
          cat_level: 0,
          cat_name: "内科用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 21,
              cat_level: 1,
              cat_name: "肠胃用药",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 27,
              cat_level: 1,
              cat_name: "退烧解热",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 31,
              cat_level: 1,
              cat_name: "长期用药",
              cat_pid: 1,

            },{
              cat_deleted: false,
              cat_id: 37,
              cat_level: 1,
              cat_name: "呼吸系统用药",
              cat_pid: 1,

            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 43,
          cat_level: 0,
          cat_name: "神经系统用药",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 44,
              cat_level: 1,
              cat_name: "睡眠不好",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 49,
              cat_level: 1,
              cat_name: "神经病变",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 55,
              cat_level: 1,
              cat_name: "心理疾病",
              cat_pid: 1,

            },
          ]
        },
        {
          cat_deleted: false,
          cat_id: 61,
          cat_level: 0,
          cat_name: "疫情防护",
          cat_pid: 0,
          children:[
            {
              cat_deleted: false,
              cat_id: 62,
              cat_level: 1,
              cat_name: "个人防护",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 67,
              cat_level: 1,
              cat_name: "家庭消毒用品",
              cat_pid: 1,

            },
            {
              cat_deleted: false,
              cat_id: 71,
              cat_level: 1,
              cat_name: "防疫常备药品",
              cat_pid: 1,

            },{
              cat_deleted: false,
              cat_id: 76,
              cat_level: 1,
              cat_name: "病原体检测",
              cat_pid: 1,

            },
          ]
        },



      ],
      // 请求参数
      queryInfo: {
        type: 3,
        pagenum: 1,
        pagesize: 5
      },
      // 总数据条数
      total: 80,
      // 为table指定列的定义
      columns: [
        {
          label: '分类名称',
          prop: 'cat_name'
        },
        {
          label: '是否有效',
          // 表示,将当前列定义为模板列
          type: 'template',
          // 表示当前这一列使用模板名称
          template: 'isok'
        },
        {
          label: '排序',
          // 表示,将当前列定义为模板列
          type: 'template',
          // 表示当前这一列使用模板名称
          template: 'order'
        },

        // {
        //   label: '操作',
        //   // 表示,将当前列定义为模板列
        //   type: 'template',
        //   // 表示当前这一列使用模板名称
        //   template: 'opt'
        // }
      ],
      // 添加对话框的分类和隐藏
      addCateDialogVisible: false,
      // 添加分类的表单数据对象
      addCateForm: {
        // 将要添加分类的名称
        cat_name: '',
        // 父级分类的ID
        cat_pid: 0,
        // 分类层级,默认要添加的是1级分类
        cat_level: 0
      },
      // 添加分类表单的验证规则对象
      addCateFormRules: {
        cat_name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }]
      },
      // 父级分类的列表
      // parentCateList: [],
      // 指定级联选择器的配置对象
      cascaderProps: {
        value: 'cat_id',
        label: 'cat_name',
        children: 'children'
      },
      // 选中的父级分类的id数组
      selectdKeys: [],
      // 编辑对话框的显示和隐藏
      editCateDialogVisbel: false,
      editCate: {},
      editCateRules: {
        cat_name: [{ required: true, message: '请输入要修改的信息', trigger: 'blur' }]
      },
      editCateId: ''
    }
  },
  created() {
    this.getCateList()
  },
  methods: {
    // 获取商品分类数据
    async getCateList() {
      const { data: res } = await this.$http.get('http://43.143.0.76:8889/api/private/v1/categories', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取商品分类失败!')
      }
      // 把数据列表赋值给cateList
      // this.cateList = res.data.result
      // 获取商品的总数量
      // this.total = res.data.total
      console.log(this.cateList)
    },
    // 监听pagesize改变
    handleSizeChange(newValue) {
      this.queryInfo.pagesize = newValue
      this.getCateList()
    },
    // 监听页码的改变
    handleCurrentChange(newpage) {
      this.queryInfo.pagenum = newpage
      this.getCateList()
    },
    // 添加分类对话框
    showAddCateDialog() {
      this.getParentCateList()
      this.addCateDialogVisible = true
    },
    // 获取父级分类的数据列表
    async getParentCateList() {
      const { data: res } = await this.$http.get('http://43.143.0.76:8889/api/private/v1/categories', {
        params: { type: 2 }
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取父级分类数据失败!')
      }
      console.log(res.data)
      console.log(this.cateList)

      // this.parentCateList = res.data
    },
    // 选中向发生变化触发
    parentCateChanged() {
      console.log(this.selectdKeys)
      // 如果 selectdKeys 数组中的length大于0证明选中父级分类
      // 反之,就说明没有选中任何父级分类
      if (this.selectdKeys.length > 0) {
        // 父级分类的id
        this.addCateForm.cat_pid = this.selectdKeys[this.selectdKeys.length - 1]
        // 为当前分类的等级赋值
        this.addCateForm.cat_level = this.selectdKeys.length
        return
      } else {
        // 父级分类的id
        this.addCateForm.cat_pid = 0
        // 为当前分类的等级赋值
        this.addCateForm.cat_level = 0
      }
    },
    // 点击按钮添加新的分类
    addCate() {
      console.log(this.addCateForm)
      this.$refs.addCateFormRef.validate(async valid => {
        if (!valid) return
        const { data: res } = await this.$http.post('http://43.143.0.76:8889/api/private/v1/categories', this.addCateForm)
        if (res.meta.status !== 201) {
          return this.$message.error('添加分类失败!')
        }
        this.$message.success('添加分类成功!')
        this.getCateList()
        this.addCateDialogVisible = false
      })
    },
    // 关闭对话框事件,重置表单数据
    addCateDialogClosed() {
      this.$refs.addCateFormRef.resetFields()
      this.selectdKeys = []
      this.addCateForm.cat_level = 0
      this.addCateForm.cat_pid = 0
    },
    async showeditCateDialog(cateInfo) {
      this.editCateId = cateInfo.cat_id
      const { data: res } = await this.$http.get('http://43.143.0.76:8889/api/private/v1/categories/' + cateInfo.cat_id)
      this.editCate = res.data
      console.log(this.editCate)
      // console.log(res.data)
      this.editCateDialogVisbel = true
    },
    // 编辑分类信息
    async editCateInfo() {
      const { data: res } = await this.$http.put('http://43.143.0.76:8889/api/private/v1/categories/' + this.editCate.cat_id, { cat_name: this.editCate.cat_name })
      if (res.meta.status !== 200) {
        return this.$message.error('更新分类数据失败!')
      }
      this.$message.success('更新分类数据成功!')
      this.getCateList()
      this.editCateDialogVisbel = false
      // console.log(res)
    },

    // 删除分类
    async removeCate(id) {
      const confirRustle = await this.$confirm('此操作将永久删除该文件, 是否继续?', '删除分类', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)

      if (confirRustle !== 'confirm') {
        return this.$message.info('已取消删除操作!')
      }

      const { data: res } = await this.$http.delete('http://43.143.0.76:8889/api/private/v1/categories/' + id)
      if (res.meta.status !== 200) {
        return this.$message.error('分类删除失败!')
      }
      this.$message.success('该分类已经成功删除!')
      this.getCateList()
    }
  }
}
</script>

<style lang="less" scoped>
.treetable {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
</style>
